package com.my.controller;


import com.my.bean.*;
import com.my.service.AlreadyAppointmentService;
import com.my.service.ExternalAlreadyService;
import com.my.service.MoenyDetailedService;
import com.my.service.RelationProjectService;
import com.my.util.SessionUtil;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 已经预约产康项目安排 （外部人员）
 * @author 闫亚茹
 *   @since 2018-08-31
 */
@Controller
@RequestMapping("/externalAlready")
public class ExternalAlreadyController {
    @Autowired
    ExternalAlreadyService externalAlreadyService;
    @Autowired
    RelationProjectService relationProjectService;
    Logger logger=Logger.getLogger(WorkguidaceController.class);
    /**
     * 查询所有的房间id和房间号
     * @return
     */
    @RequestMapping("/selectexternalAlready")
    @ResponseBody
    public List<ExternalAlready> select(HttpSession session){

        List<ExternalAlready> list = externalAlreadyService.selectResult();
        return list;
    }


    /**
     * 根据房间id查询每个房间有哪些项目
     * @param externalAlready
     * @return
     */
    @RequestMapping("/selectHomeById")
    @ResponseBody
    public List<ExternalAlready> selectHomeById(ExternalAlready externalAlready,HttpSession session){
        boolean admin=false;
        //如果事超级管理员  即可查看所有的房间  判断是否为超级管理员
        if(SessionUtil.getSessionUser(session).getRoles().getRoleValue().equals("9f77d5a8-75c6-4d06-adf9-a37e727d491a")){
            admin=true;
        }
        List<ExternalAlready> list = externalAlreadyService.selectHomeById(externalAlready.getHomeId());
        return list;
    }


    @RequestMapping("/insert")
    @ResponseBody
    public String insert(ExternalAlready externalAlready){
        if(externalAlreadyService.insert(externalAlready)){
            logger.info("{insert|保存成功}");
            return "保存成功";
        }else{
            logger.info("{insert|保存失败}");
            return "保存失败";
        }
    }


    //TODO 已废弃
    /**
     * 查询所有
     * @param lin
     * @param data
     * @param voPage
     * @return
     */
    @RequestMapping("findExternalAlready")
    @ResponseBody
    public ResultPage<ExternalAlready> findExternalAlready(String lin, String data, VoPage voPage,HttpSession session){
        Map map=new HashMap();
        map.put("lin",lin);
        map.put("data",data);
        ResultPage<ExternalAlready> resultPage = externalAlreadyService.selectMyPage(map,voPage);
        return  resultPage;
    }

    /**
     * /已经预约跳转页面
     * @return
     */
    @RequestMapping("/noOrderHandling")
    public String noOrderHandling(){
        return "noOrder_handlings";

    }

    @RequestMapping("/addMoenyDtatiled")
    @ResponseBody
    public String addMoenyDtatiled(Long projectId,String userName,String projectName,Integer pice){
        RelationProject relationProject=new RelationProject();
        relationProject.setProjectId(projectId);
        relationProject.setCreateTime(new Date().getTime());
        relationProject.setInside(2);
        relationProject.setUserName(userName);
        if(relationProjectService.insert(relationProject)){
            return  "预约成功";
        }else{
            return  "预约失败";
        }

    }










}
